package com.altorithm;

/**
 * @Classname ShellSort
 * @Date 2019/9/25 10:55
 * @auther by hqy
 */
public class ShellSort {

    public static void sort(int[] array) {
        for (int gap = array.length / 2; gap > 0; gap = gap / 2) {
            for (int i = gap; i < array.length; i = i + gap) {
                int insertIndex = i;
                int insertValue = array[i];
                for (int j = i - gap; j >= 0; j = j - gap) {
                    if (array[j] > insertValue) {
                        array[j + gap] = array[j];
                        insertIndex = j;

                    }
                }
                if (insertIndex != i) {
                    array[insertIndex] = insertValue;
                }

            }
        }
    }
}
